# -*- coding:utf-8 -*—
import os

import pandas as pd
# d={'one':{'a':1,'b':2,'c':3,'d':4},'two':{'a':5,'b':6,'c':7,'d':8},'three':{'a':9,'b':10,'c':11,'d':12}}
# df=pd.DataFrame(d)
# print(df)
pointdict = {"PLPTNO": "管线点号",
             "MNTPCD": "要素类型编码",
             "AUXNO": "附属物要素编码",
             "X": "X坐标",
             "Y": "Y坐标",
             "GRDEL": "地面高程",
             "CHR": "特征",
             "AUX": "附属物",
             "ADDVCD": "行政区划代码",
             "WLDP": "井深",
             "WLSZ": "井尺寸",
             "WLMTR": "井材质",
             "MPPTNO": "图上点号",
             "SHTNO": "图幅号",
             "USST": "使用状态",
             "CRRD": "所在道路",
             "BLDYR": "建设年份",
             "OWNER": "权属单位",
             "PRBDT": "探测日期",
             "PRBUN": "探测单位",
             "SPUN": "监理单位",
             "ECC": "偏心距",
             "WLBTDP": "井底深",
             "SMBANG": "符号角度",
             "WLCVSHP": "井盖形状",
             "WLCVSZ": "井盖尺寸",
             "WLCVMTR": "井盖材质",
             "WLCVEL": "井盖高程",
             "WLSHP": "井室形状",
             "NT": "备注",
             "PIBATCH": "管网批次",
             "pipegroupkind": "组分类别",
             "facilitieskind": "设备类型",
             "draindeep": "管底埋深",
             "specification": "规格(口径、尺寸)",
             "facilitiesmaterial": "设备材质",
             "accesspoint": "是否为接驳点",
             "wellfoul": "检查井淤堵",
             "waterfloordeep": "水面高差",
             "wellstatus": "检查井状态",
             "mixedpoint": "混接点情况",
             "coverok": "井盖是否一致",
             "householdinfo": "户出信息",
             "datasource": "数据来源",
             "pipepointkind": "管点类别",
             "pipedoor": "是否有拍门",
             "interceptor": "是否截流井",
             "GEOM": "空间几何数据"
             }
linedict ={"PLID":"管线标识",
"MNTPCD":"要素类型编码",
"PLPT0":"起始管点号",
"PLPT1":"终止管点号",
"PLPT0DP":"起始管点埋深",
"PLPT1DP":"终止管点埋深",
"PLPT0HT":"起始管点高程",
"PLPT1HT":"终止管点高程",
"ADDVCD":"行政区划代码",
"PPLN":"管线长度",
"PPDM":"管径",
"FLDR":"流向",
"MTR":"材质",
"LNTP":"线型",
"LAYTP":"埋设方式",
"USST":"使用状态",
"CRRD":"所在道路",
"BLDYR":"埋设年份",
"OWNER":"权属单位",
"PRBDT":"探测日期",
"PRBUN":"探测单位",
"SPUN":"监理单位",
"CBCNT":"线缆条数",
"HLCNT":"总孔数",
"USDHLCNT":"已用孔数",
"HLDM":"孔径",
"PRS":"压力",
"VLT":"电压",
"NT":"备注",
"PIBATCH":"管网批次",
"pipegroupkind":"组分类别",
"pipestatus":"管道状态",
"pipeprimary":"管道主次",
"pipekind":"管道类别",
"irrigationkind":"渠道类型",
"WATERFLOW":"流速"
}

def renameExcel(filepath,dic,fileName):
    # path=os.getcwd()
    # filepath=os.path.join(path,"管点.xlsx")
    print(filepath)
    df = pd.read_excel(io=filepath)
    # 返回第一行
    # print(df.loc[0])
    for index, row in df.iteritems():
        print(index) # 输出列名
        for key, value in dic.items():
            # print("\nKey: " + key)
            # print("Value: " + str(value))
            if(index==str(key)):
                df.rename(columns={index: value}, inplace=True)

    df.to_excel(fileName)
    print("——----完成——————————")
# df.head()

if __name__ == '__main__':
    #处理点表
    pointP="F:/data/4.yingtan/2022.09.19鹰潭数据处理/2022年9月19日导出数据/cj_pl_p.xlsx"
    pointP_new="F:/data/4.yingtan/2022.09.19鹰潭数据处理/2022年9月19日导出数据/cj_pl_p_new.xlsx"

    lineP="F:/data/4.yingtan/2022.09.19鹰潭数据处理/2022年9月19日导出数据/cj_pl_l.xlsx"
    lineP_new="F:/data/4.yingtan/2022.09.19鹰潭数据处理/2022年9月19日导出数据/cj_pl_l_new.xlsx"
    # 点表
    # renameExcel(pointP,pointdict,pointP_new)
    # 线表
    renameExcel(lineP,linedict,lineP_new)

